import { INCREMENTCOUNT, DECREMENTCOUNT } from "../constant/countConstant"

const init = {
  count: 0
}

export default function countReducer(preState = init, action) {
  const { type, data } = action

  // 判断
  switch (type) {
    case INCREMENTCOUNT:
      return { ...init, count: preState.count + data };
    case DECREMENTCOUNT:
      return { ...init, count: preState.count - data };
  }

  return preState
}